package com.xrtn.controller;

import com.xrtn.ApiVersion;
import com.xrtn.service.IDoctorService;
import com.xrtn.utils.CodeEnum;
import com.xrtn.utils.ObjUtils;
import com.xrtn.utils.PropertyUtil;
import com.xrtn.utils.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

import java.util.Map;
import java.util.Properties;

/**
 * Created by tu_pei on 2018/2/26.
 */

@Api("验证接口")
@Controller
@RequestMapping("/{version}/auth")
public class AuthController {

    @Autowired
    private IDoctorService authService;
    /**
     * @param @param  account
     * @param @param  userPwd
     * @param @return
     * @return ResponseData
     * @throws
     * @Title: sign
     * @Description: 登录
     */
    @ApiOperation(value = "登录", notes = "登录")
    @RequestMapping(value = "/online", method = RequestMethod.POST)
    @ApiVersion(1)
    @ResponseBody
    public ResponseData online() {
        ResponseData data = new ResponseData();
        Integer online = Integer.parseInt(PropertyUtil.getProperty("online"));

        if(online == 1){
            data.setResults(false);
        }else{
            data.setResults(true);
        }
        return data;
    }

    /**
     * @param @param  account
     * @param @param  userPwd
     * @param @return
     * @return ResponseData
     * @throws
     * @Title: sign
     * @Description: 登录
     */
    @ApiOperation(value = "登录", notes = "登录")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "account", dataType = "string", required = true, value = "账号", defaultValue = "13888888888"),
            @ApiImplicitParam(paramType = "query", name = "userPwd", dataType = "string", required = true, value = "密码", defaultValue = "123456")
    })
    @RequestMapping(value = "/sign", method = RequestMethod.POST)
    @ApiVersion(1)
    @ResponseBody
    public ResponseData sign(String account, String userPwd) {
        // 创建响应Model
        ResponseData data = new ResponseData();
        // 调用Service
        Map<String, Object> resultMap = authService.sign(account, userPwd);
        // 获取返回信息
        CodeEnum resultMsg = (CodeEnum) resultMap.get("EnumCode");
        // 如果不为空
        if (ObjUtils.isNotEmpty(resultMsg)) {
            // 设置返回数据
            data.setCodeEnum(resultMsg);
        }
        // 设置返回对象
        data.setResults(resultMap.get("userInfo"));
        // 返回数据
        return data;
    }

    /**
     * @param @param  account
     * @param @param  userPwd
     * @param @return
     * @return ResponseData
     * @throws
     * @Title: sign
     * @Description: 登录
     */
    @ApiOperation(value = "登录", notes = "登录")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "account", dataType = "string", required = true, value = "账号", defaultValue = "13888888888"),
            @ApiImplicitParam(paramType = "query", name = "userPwd", dataType = "string", required = true, value = "密码", defaultValue = "123456")
    })
    @RequestMapping(value = "/signTest", method = RequestMethod.POST)
    @ApiVersion(1)
    @ResponseBody
    public ResponseData signTest(String account, String userPwd) {
        // 创建响应Model
        ResponseData data = new ResponseData();
        // 调用Service
        Map<String, Object> resultMap = authService.sign(account, userPwd);
        // 获取返回信息
        CodeEnum resultMsg = (CodeEnum) resultMap.get("EnumCode");
        // 如果不为空
        if (ObjUtils.isNotEmpty(resultMsg)) {
            // 设置返回数据
            data.setCodeEnum(resultMsg);
        }
        // 设置返回对象
        data.setResults(resultMap.get("userInfo"));
        // 返回数据
        return data;
    }


//    /**
//     * @Title: resetPwd
//     * @Description: B端，用户修改密码
//     * @param @param userTel
//     * @param @param userCode
//     * @param @param userPwd
//     * @param @return
//     * @return ResponseData
//     * @throws
//     */
//    @ApiOperation(value = "B端|商户修改密码",notes="B端用户修改密码")
//    @ApiImplicitParams({
//            @ApiImplicitParam(paramType="query",name="userTel",dataType="string",required=true,value="手机号",defaultValue = "13888888888"),
//            @ApiImplicitParam(paramType="query",name="userCode",dataType="string",required=true,value="验证码"),
//            @ApiImplicitParam(paramType="query",name="userPwd",dataType="string",required=true,value="密码",defaultValue = "123456")
//    })
//    @RequestMapping(value = "/resetPwd",method = RequestMethod.POST)
//    @ApiVersion(1)
//    @ResponseBody
//    public ResponseData resetPwd(String userTel,@RequestParam(required = false)String userCode,String userPwd){
//
//        // 创建响应Model
//        ResponseData data = new ResponseData();
//        // 调用Service
//        Map<String, Object> resultMap = userServerService.doUserUpdatePwd(userTel, userCode, userPwd,SysConstant.GGLING_AD_PLATFORM_B);
//
//        // 获取返回信息
//        CodeEnum resultMsg = (CodeEnum) resultMap.get("EnumCode");
//        // 如果不为空
//        if (ObjUtils.isNotEmpty(resultMsg)) {
//            // 设置返回数据
//            data.setCodeEnum(resultMsg);
//        }
//        // 设置返回对象
//        data.setResults(resultMap.get("userInfo"));
//        // 返回数据
//        return data;
//    }
//
//
//    /**
//     * @Title: updateUser
//     * @Description: B端，用户修改信息
//     * @param @param userId
//     * @param @param userName
//     * @param @param userAddres
//     * @param @param userTel
//     * @param @param userLogo
//     * @param @param userBusinessImg
//     * @param @return
//     * @return ResponseData
//     * @throws
//     */
//    @ApiOperation(value = "B端|商户修改信息",notes="B端商户认证")
//    @ApiImplicitParams({
//            @ApiImplicitParam(paramType="query",name="userId",dataType="int",required=true,value="用户id",defaultValue = "4"),
//            @ApiImplicitParam(paramType="query",name="userName",dataType="string",required=true,value="公司名称"),
//            @ApiImplicitParam(paramType="query",name="userAddress",dataType="string",required=true,value="公司地址"),
//            @ApiImplicitParam(paramType="query",name="userTel",dataType="string",required=true,value="公司电话"),
//            @ApiImplicitParam(paramType="query",name="userLogo",dataType="string",required=true,value="公司Logo"),
//            @ApiImplicitParam(paramType="query",name="userBusinessImg",dataType="string",required=true,value="营业执照")
//    })
//    @RequestMapping(value = "/updateUser",method = RequestMethod.POST)
//    @ResponseBody
//    public ResponseData updateUser(UserInfoB userInfoB) {
//
//        // 创建响应Model
//        ResponseData data = new ResponseData();
//        // 通过Id获取该商户DB中数据
//        UserInfoB dbUb = userService.selectByUserPhone(userInfoB.getUserTel());
//        // 如果DB中商户数据不为空
//        if (ObjUtils.isNotEmpty(dbUb)) {
//            // 如果当前商户已认证
//            if (dbUb.getIsCertification() != 1) {
//                // 修改用户数据
//                userService.updateByUserId(userInfoB);
//                // 设置参数
//                data.setResults(userInfoB);
//            } else {
//                // 设置返回数据
//                data.setCodeEnum(CodeEnum.CODE_40001);
//                // 直接返回
//                return data;
//            }
//        } else {
//            // 该用户不存在
//            data.setCodeEnum(CodeEnum.CODE_10003);
//        }
//        return data;
//    }

}
